<?php
namespace app\index\controller;
use think\Config;
use think\Request;
use think\Validate;
class Form extends Base
{
    public function formDemo(Request $request){
        var_dump($request ->param());
        if($request ->isGet()){
            return $this ->fetch();
        }else{
            $rule = [
                ['username','require|max:25','请填写昵称|昵称最多不能超过25个字符'],
                ['password','require|min:6|max:20|confirm:password_confirm','请填写密码|密码位数不能小于6位并且不能超过20位|两次密码输入不一致'],
                ['email','require|email','请填写邮箱|邮箱格式有误']
            ];

            $data = [
                'username'  => $request ->param('username'),
                'password'   => $request ->param('password'),
                'email' => $request ->param('email'),
            ];
            $validate = new Validate($rule);
            $result   = $validate->check($data);
            if(!$result){
                $this ->error($validate->getError());
            }else{
                $this ->success('验证成功');
            }
        }
    }
}
